import util from "../../common/js/util.js";
var app = getApp();
var base_width = 60;
var base_height = 39;

/**
 * 这个组件是为了避免 i-popover 和table循环依赖而诞生的，主用还是table1
 */

Component({
  mixins: [],
  data: {
    labelList1: [
      { text: "预计使用时间", name: "TIME5" },
      { text: "品名", name: "MATERIAL_NAME" },
      { text: "固定资产", name: "FIXED_ASSETS" },
      { text: "规格", name: "MODEL" },
      { text: "数量", name: "NUM" },
      { text: "单位", name: "METERING_NAME" },
      { text: "品牌要求", name: "BRAND" },
    ],
    dataList1: [
      {
        TIME5: "2022-03-29",
        MATERIAL_NAME: "镀锌铁丝",
        FIXED_ASSETS: "否",
        MODEL: "22#",
        NOTE: "",
        NUM: "6",
        METERING_NAME: "/",
        BRAND: "无"
      },
      {
        TIME5: "2022-03-29",
        MATERIAL_NAME: "铁棒",
        FIXED_ASSETS: "否",
        MODEL: "22#",
        NOTE: "",
        NUM: "6",
        METERING_NAME: "/",
        BRAND: "无"
      }
    ],

    // labelList2: [
    //   { text: "供应商1号"}
    // ],

    tableHeight: 0,
    tableWidth1: 0,
    tableWidth2: 0,
    scrollY2_1: 0,
    scrollY2_2: 0,
    left: 0,
    right: 0,
    disMove3: false,
    move: true
  },
  props: {
    labelList: Array,
    dataList: Array
  },
  onInit() {
    // console.log(app.prototype.screenHeight);
   // console.log(app.prototype.windowWidth);
    let row_width = 0;
    let tableWidth1 = 0;
    if (this.props.labelList.length >= 6) {
      row_width = base_width;
      tableWidth1 = (row_width + 1) * (this.props.labelList.length);
    } else {
      row_width = Math.round(app.prototype.windowWidth / this.props.labelList.length);
      // console.log("---ss:"+app.prototype.windowWidth);
      tableWidth1 = Math.round((app.prototype.windowWidth - 10));
    }
    // console.log(row_width,this.props.labelList.length);

    // let tableWidth1=(row_width + 1) * (this.props.labelList.length);

    // console.log(tableWidth1);

    // console.log(tableWidth1);

    this.setData({
      tableHeight: (this.props.dataList.length) * base_height - 6,
      tableWidth1,
      labelList1: this.props.labelList,
    })
  },

  didMount() {
    this.setData({
      dataList1: this.props.dataList
    })
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    onTouchStart() {
      this.setData({
        disMove3: true,
        move: false
      })
      // console.log("--触摸开始disMove3:",this.data.disMove3);
    },
    onTouchEnd() {
      this.setData({
        disMove3: false,
        move: true
      })
      // console.log("--触摸结束disMove3:",this.data.disMove3);
    },
    tableItemClick(e) {
      let value = e.currentTarget.dataset.value;
      dd.alert({
        content: value
      })
    },
    initData(list) {
      // console.log(list);
      let row_width = 0, tableWidth1 = 0;
      if (this.props.labelList.length >= 6) {
        row_width = base_width;
        row_width = Math.round((app.prototype.windowWidth / 6));
        tableWidth1 = (row_width + 1) * (this.props.labelList.length) + 1;
        // debugger
      } else {
        ///windowWidth ->px
        row_width = Math.round(app.prototype.windowWidth / this.props.labelList.length);
        tableWidth1 = Math.round((app.prototype.windowWidth - 3));
        // console.log("---ss:"+app.prototype.windowWidth);  
      }
      // let tableWidth1=(row_width + 1) * (this.props.labelList.length) + 1;
      // console.log(row_width,this.props.labelList.length);
      // let tableWidth1=Math.round((app.prototype.windowWidth-3));
     // console.log(tableWidth1);
      //debugger
      this.setData({
        tableHeight: (list.length) * base_height ,
        dataList1: list,
        tableWidth1
      })
    },
    scrollY(e) {
      this.setData({
        scrollTop: e.detail.scrollTop,
      });
    },
    scrollY2_1fn(e) {
      this.setData({
        scrollY2_2: e.detail.scrollTop,
      });
    },
    scrollX2_1(e) {
      this.setData({
        right: 0,
        left: 1,
        scrollX2_1: e.detail.scrollLeft,
      });

    },
    scrollX(e) {
      this.setData({
        scrollLeft: e.detail.scrollLeft,
      });
    },
    i_popover(ref){
      this.i_popover=ref;
    },
    openPopover(e){
      let index=e.currentTarget.dataset.index;
      let pindex=e.currentTarget.dataset.pindex;
      let obj={};
      this.i_popover.openFn(obj);
    }
  },
});
